package com.xbongbong.saas.model.impl;

import com.xbongbong.admin.domain.entity.MarketDetailEntity;
import com.xbongbong.paas.enums.DelEnum;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.paas.toolbox.util.DateUtil;
import com.xbongbong.pro.domain.dao.MarketDetailDao;
import com.xbongbong.saas.model.MarketDetailModel;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @Author: shian
 * @Date: 2020/2/13 13:48
 * @Description:
 */
@Service("marketDetailModel")
public class MarketDetailModelImpl implements MarketDetailModel {

    @Resource
    private MarketDetailDao marketDetailDao;

    @Override
    public Integer insert(MarketDetailEntity entity) throws XbbException {
        long now = DateUtil.getInt();
        entity.setAddTime(now);
        entity.setUpdateTime(now);
        entity.setDel(DelEnum.NORMAL.getDel());
        return marketDetailDao.insert(entity);
    }

    @Override
    public Integer update(MarketDetailEntity entity) throws XbbException {
        entity.setUpdateTime((long)DateUtil.getInt());
        return marketDetailDao.update(entity);
    }

    @Override
    public int save(MarketDetailEntity marketDetailEntity) throws XbbException {
        if (marketDetailEntity.getId() == null || marketDetailEntity.getId() == 0) {
            return insert(marketDetailEntity);
        }
        return update(marketDetailEntity);
    }
    @Override
    public List<MarketDetailEntity> findEntitys(Map<String, Object> param) {
        return marketDetailDao.findEntitys(param);
    }

    @Override
    public Integer getEntitysCount(Map<String, Object> param) {
        return marketDetailDao.getEntitysCount(param);
    }

    @Override
    public List findEntitysWithoutSub(Map<String, Object> param) {
        return null;
    }

    @Override
    public MarketDetailEntity getByKey(Long key) throws XbbException {
        return marketDetailDao.getByKey(key);
    }

    @Override
    public List<MarketDetailEntity> publishMarket() {
        return marketDetailDao.getByPublish();
    }

    @Override
    public List<MarketDetailEntity> bannerByPublish() {
        return marketDetailDao.getBannerByPublish();
    }

    @Override
    public int batchUpdate(List<MarketDetailEntity> marketList) throws XbbException {
        return marketDetailDao.batchUpdate(marketList);
    }
}